<include file="__PUBLIC__/_header" />
<link href="__APP_SKIN__js/uploadify/uploadify.css?2" rel="stylesheet" type="text/css" />

<div class="main-container" id="main-container">

     <div class="main-content" style="margin-left: 0;">
            <div class="page-content">
                <!-- /.page-header -->
                <div class="row">
                    <div class="col-xs-12">
                        <div class="row">
                            <div class="col-sm-12">
                                <form class="form-horizontal" id="myform" role="form"  method="post" name="edit-form" >
									<input type="hidden" name="op" value="edit">
									<input type="hidden" name="id" value="{$adv_id}">
									<input type="hidden" name="data[place_id]" value="{$place_id}">
						
                                    <div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 更新时间 </label>
										<div class="col-sm-6">
										<input type="text" readonly id="update_time" name="data[update_time]" placeholder="" value="{$data.update_time}" class="col-xs-10 col-sm-8" />
										</div>
									</div>
									
									<div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 广告类型 </label>
										<div class="col-sm-3">
										{$htmls.type_html}
										</div>
									</div>
									
									<div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 广告图片 </label>
										<div class="col-sm-9">
											<img src="{:Controller::getConfig('file_server_url')}/2013/{$data.image}" width="340" height="140" >
											<a id="b_pic1" idx="1" name="file_upload"  multiple="true" >上传</a>
										</div>
									</div>

									<div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 广告位置 </label>
										<div class="col-sm-3">
										{$htmls.pos_html}
										</div>
									</div>
									
									
									<div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 网页 </label>
										<div class="col-sm-4">
											<input type="text" id="form_m_price" name="data[url]" value="{$data.url}"   class="col-xs-10 col-sm-12" />
										</div>
										<span class="help-inline col-xs-12 col-sm-6">
												<span class="middle" id="form_m_price_tips" style="color:red;"></span>
										</span>
									</div>
									
									
									<div class="form-group">
										<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 链接编号 </label>
										<div class="col-sm-3">
											<input type="text" id="form_m_usual_price" name="data[m_id]"  placeholder="{$data.m_id}" value="{$data.m_id}" class="col-xs-10 col-sm-12" />
										</div>
										<span class="help-inline col-xs-12 col-sm-6">
												<span class="middle" id="form_m_usual_price_tip" style="color:red;"></span>
										</span>
									</div>
									
									
								
									<div class="col-md-offset-2 col-md-9">
                                            <label class="col-sm-3 control-label no-padding-right" for="form-field-1">  </label>
											<button class="btn btn-info" type="button" onclick="chk_form();">
												<i class="icon-ok bigger-110"></i>
												提交
											</button>
											&nbsp; &nbsp; &nbsp;
											<button class="btn" type="reset">
												<i class="icon-undo bigger-110"></i>
												重置
											</button>
									</div>
                                </form>
                            </div>
							
                            <!-- /span -->
                        </div>
                        <!-- /row -->
                    </div>
                    <!-- PAGE CONTENT ENDS -->
                </div>
                <!-- /.row -->
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="update_img" value="{$arr['img']}">
<input type="hidden" id="uploadSwf" value="__APP_SKIN__js/uploadify/uploadify.swf">
<input type="hidden" id="uploader" value="{:Controller::createUrl('vis/file/index')}">
<input type="hidden" id="service_url" value="{:Controller::getConfig('file_server_url')}">

<script src="__APP_SKIN__js/jquery-2.0.3.min.js"></script>
<script src="__APP_SKIN__js/bootstrap.min.js"></script>
<script src="__APP_SKIN__js/uploadify/jquery.uploadify.js?12" type="text/javascript"></script>
<script>

    function chk_form(){

        /*if($('#form_m_price').val() ==0 || $('#form_m_price').val() ==''){
            $('#form_m_price').focus();
			$('#form_m_price_tips').html('订货单价不能为0或空');
            return false;
        }
        if($('#form_m_usual_price').val() ==0 || $('#form_m_usual_price').val() ==''){
            $('#form_m_usual_price').focus();
            $('#form_m_usual_price_tip').html('销售价价格不能为0或空');
            return false;
        }*/
        var url = "{:Controller::_createUrl('advert/edit/')}";
        ajax_submit_form(url,'myform');
    }

    function ajax_submit_form(url,obj){
	
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: url ,//url
            data: $('#'+obj).serialize(),
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.resultCode == 200) {
                    window.parent.location.reload();
                }else{
					alert('广告添加失败');
				}
            },
            error : function() {
                return false;
            }
        });
	}

   
    $(function () {

        var url = $('#dataupdate').val();
        $('#dataupdate_button').click(function () {
            var is_img = $('#update_img').val();
            
            var img = '';
            if (is_img == 1) {
                img = $("input[name='upload_files']").map(function (index, elem) {
                    return $(elem).val();
                }).get().join(',');
                if (img == '') {
                    bootbox.dialog({
                        message: "<span class='btn-sm btn-danger'>请上传图片</span>"
                    });
                    return false;
                }
            }   
        })
        upload($("a[name=file_upload]"));
        bind_del_pic();
    })


    function upload(obj) {
        var swf = $("#uploadSwf").val();
        var uploader = $("#uploader").val();
        $(obj).uploadify({
            'height': 140,
            'width': 140,
            'multi': true,
            'formData': {'file_type': 0},
            'swf': swf,    //指定上传控件的主体文件
            'uploader': uploader,    //指定服务器端上传处理文件
            'fileTypeExts': '*.jpg',  //jpeg;*.gif;*.png
            'fileTypeDesc': 'Image Files',
            'fileSizeLimit': '4096KB',
            'buttonText': "",
            'queueSizeLimit': 50,
            //检测FLASH失败调用
            'onFallback': function () {
                alert("您的浏览器未安装FLASH控件，无法上传图片，请安装FLASH控件后再试！");
            },
            //返回一个错误，选择文件的时候触发
            'onSelectError': function (file, errorCode, errorMsg) {
                switch (errorCode) {
                    case -100:
                        alert("上传的文件数量已经超出限制的" + $('a[name=file_upload]').uploadify('settings', 'queueSizeLimit') + "个文件！");
                        break;
                    case -110:
                        alert("文件 [" + file.name + "] 大小超出系统限制的" + $('a[name=file_upload]').uploadify('settings', 'fileSizeLimit') + "大小！");
                        break;
                    case -120:
                        alert("文件 [" + file.name + "] 大小异常！");
                        break;
                    case -130:
                        alert("文件 [" + file.name + "] 类型不正确！");
                        break;
                }
            },
            'onUploadError': function (file, errorCode, errorMsg, errorString) {
                alert(errorString);
            },
            'onUploadSuccess': function (file, data, response) {
                var service_url = $("#service_url").val();
                ;
                var jsons = "/2013/" + data;
                if ($(".no_pic").length > 0) {
                    $(".no_pic").remove();
                }
                $("<div style='max-width:200px;height:140px;float: left;text-align: center'><input type='hidden' name='upload_files' value='" + data + "' />" +
                    "<img class='preview-upload-pic' style='height:110px;max-width:160px; margin:5px;' src='" + service_url + jsons + "'/>&nbsp;" + data + "<br/><a href='javascript:void(0);' file_name='" + data + "'class='del_pic'>删除</a><br/><br/><br/></div>").insertBefore($('#' + file.id).parent());
                bind_del_pic();
            }
        });
    }


    function bind_del_pic() {
        $(".del_pic").click(function () {
            $(this).parent().remove();
            $("#del_attch").append("<input type='hidden' name='deled_pic[]' value='" + $(this).attr('file_name') + "' />");
        });
    }

</script>
</body>
</html>